﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Utils;

namespace WCS.Helpers
{
    public class WcsHelper
    {
        public static int UpdateRobotInfoValue(int Seqid, string ItemType, string DevNo, int Unitindex, string Value, ref int iErrorCode, ref string sErrorText)
        {
            int Errorcode = 88;
            string ErrorText = "";
            using (SqlSugarClient db = DBContext.GetInstance())
            {
                try
                {
                    List<SugarParameter> paramArrar = new List<SugarParameter>()
                    {
                        new SugarParameter("@iErrorCode", null, true),//设置为output
                        new SugarParameter("@vErrorText", null, true),//设置为output
                        new SugarParameter("@iseqid", Seqid),
                        new SugarParameter("@vItemType", ItemType),
                        new SugarParameter("@vDevNo", DevNo),
                        new SugarParameter("@vValue", Value)
                    };
                    var dt = db.Ado.UseStoredProcedure().GetDataTable("SP_0_READ_UPDATE_PLC_ITEM", paramArrar);
                    
                    Errorcode = int.Parse(paramArrar[0].Value.ToString());
                    ErrorText = paramArrar[1].Value.ToString();
                    if (Errorcode < 88)
                    {
                        LogHelper.WriteError("读取" + Unitindex.ToString() + "号机械手Robot_Info值更新数据库失败!错误代码：" + Errorcode.ToString() + ErrorText);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError("异常：读取" + Unitindex.ToString() + "号Robot_Info值更新数据库失败!错误代码：" + Errorcode.ToString() + ex.Message.ToString());
                }
            }
            return Errorcode;
        }

    }
}
